import { Checkbox, Col, Divider, Form, InputNumber,message,Row, Select, Switch} from "antd";
import React from "react";
import styles from "./index.less"
import { modelListTenant, updateModelListTenant } from "@/services/languageModel";
import { baseInfoDetail,baseInfoEdit } from "@/services/tenantManagement";
import PackageReadonly from "../ChargingManage/packageManage/packageReadonly";

class ResourceLimitation extends React.Component{
  constructor(props){
    super(props);
    this.state = {

    }
  }

  componentDidMount(){
    if(this.props.onRef){
      this.props.onRef(this)
    }

  }

  initData = () => {

  }

  getDetail = async (tenantId) => {
    const res = await baseInfoDetail({tenantId})
    this.props.form.setFieldsValue({billFlag:res.billFlag == 0 ? true : false})
    this.getPackageDetail(res.planDetail.packageId)
  }

  checkFormData = () => {
    this.props.form.validateFields((error,values) => {
      if(!error){
        values.billFlag =  values.billFlag ? 0 : 1
        if(this.props.tenantId){
          this.doEdit(values)
        }else{
          this.props.setFormData({
            step:2,
            nextStep:3,
            value:values
          })
        }

        
      }
    })
  }


  doEdit = async data => {
    const res = await baseInfoEdit({id:this.props.tenantId,...data})
    if(res.code != -1){
      message.info(res.message)
    }
  }

  getPackageDetail = id => {
    this.PackageReadonly.initModal({id},true)
  }

  render(){
    const { form:{getFieldDecorator},id,current } = this.props
    const { modelList,activeModelIds,activeModelList,indeterminateModel,checkModelAll,activeEmbeddingModelIds,embeddingModelList,agentModelList,activeAgentModelIds } = this.state;
    const formItemLayout = {
      labelCol: { span: 4 },
      wrapperCol: { span: 18 },
    };
    
    return(
      <div style={{display:current == 2 ? "block" : "none",marginBottom:20}}>
        <Form {...formItemLayout}>
          <Form.Item label="是否开启账单">
            {getFieldDecorator('billFlag', { valuePropName: 'checked' })(<Switch />)}
          </Form.Item>
        </Form>
        <PackageReadonly onRef={ref => this.PackageReadonly = ref} />
        
      </div>
    )
  }
}

export default Form.create()(ResourceLimitation)